package com.boot2.core.dao;

import com.boot2.core.utils.SnowflakeIdFactory;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

/**
 * @author zhangweilin
 * @date 2020/4/24 15:32
 * @Description: 雪花算法 id
 */
public class SnowflakeGenerator implements IdentifierGenerator {
    public static final String TYPE = "com.boot2.core.dao.SnowflakeGenerator";


    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return SnowflakeIdFactory.generateId();
    }
}
